package com.lagou.task;

import java.util.*;

public class Test05 {

    public static void main(String[] args) {

        Test05 test05 = new Test05();
        test05.preparationPoker();

        test05.sendCards();

        System.out.println("玩家A手中的牌是:");
        test05.printCard(test05.playerA);

        System.out.println("玩家B手中的牌是:");
        test05.printCard(test05.playerB);

        System.out.println("玩家C手中的牌是:");
        test05.printCard(test05.playerC);

        System.out.println("底牌是:");
        test05.printCard(test05.bottomCard);
    }

    /**
     * 扑克牌堆
     */
    Map<Integer, String> poker = new HashMap<>();

    /**
     * 玩家A手中的牌
     */
    List<Integer> playerA = new LinkedList<>();
    /**
     * 玩家B手中的牌
     */
    List<Integer> playerB = new LinkedList<>();
    /**
     * 玩家C手中的牌
     */
    List<Integer> playerC = new LinkedList<>();
    /**
     * 底牌
     */
    List<Integer> bottomCard = new LinkedList<>();

//    准备 54 张扑克牌并打乱顺序
    private void preparationPoker() {

        List<String> color = new ArrayList<>();

        color.add("黑桃");
        color.add("红桃");
        color.add("梅花");
        color.add("方片");

        List<String> point = new ArrayList<>();
        String[] point_names = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
        for (int i = 0;i < 13;i++) {
            point.add(point_names[i]);
        }

        int k = 1;
        poker.put(k++, "大王");
        poker.put(k++, "小王");

        // 1~ 13分别代表A, 2,3....,10,J, Q, K;  -1代表大王, 0代表小王
        for (int i = 0;i < 13;i++) {
            for (int j = 0;j < 4;j++) {
                if (0 == i) {
                    String s = color.get(j) + point.get(i + 1);
                    poker.put(k++, s);
                }

                else if (1 == i) {
                    String s = color.get(j) + point.get(i - 1);
                    poker.put(k++, s);
                }
                else {
                    String s = color.get(j) + point.get(14 - i);
                    poker.put(k++, s);
                }
            }
        }
    }

    //发牌
    private void sendCards() {

        List<Integer> pokerKeyLists = new ArrayList<>();
        for (int i = 1;i <= 54;i++) {
            pokerKeyLists.add(i);
        }

        Collections.shuffle(pokerKeyLists);

        for (int i = 0;i < 51; i++) {
            int num = i % 3;
            switch (num) {
                case 0:
                    playerA.add(pokerKeyLists.get(i));
                    break;
                case 1:
                    playerB.add(pokerKeyLists.get(i));
                    break;
                case 2:
                    playerC.add(pokerKeyLists.get(i));
                    break;
            }
        }

        bottomCard.add(pokerKeyLists.get(51));
        bottomCard.add(pokerKeyLists.get(52));
        bottomCard.add(pokerKeyLists.get(53));
    }

    private void printCard(List<Integer> list) {

        Collections.sort(list);

        for (Integer tmp : list) {
            String str = poker.get(tmp);
            System.out.print(str + " ");
        }

        System.out.println("\n");
    }
}
